import logging

import requests

import app


class Sector:
    def __init__(self, token):
        self.header_dict = {"Authorization": token}
        self.url = app.Base_HOST + "/api/company/department"
        self.url_id = app.Base_HOST + "/api/company/department/{}"

    # 新增部门
    def add_sec(self, json_dict):
        res_add = requests.post(url=self.url, headers=self.header_dict, json=json_dict)
        logging.info("新增部门接口返回的数据:{}".format(res_add.json()))
        return res_add

    # 查询部门
    def query_sec(self, id):
        res = requests.get(url=self.url_id.format(id), headers=self.header_dict)
        logging.info("查询部门接口返回的数据:{}".format(res.json()))
        return res

    # 修改部门
    def update_sec(self, id, json_dict):
        res = requests.put(url=self.url_id.format(id), headers=self.header_dict, json=json_dict)
        logging.info("修改部门接口返回的数据:{}".format(res.json()))
        return res

    # 删除部门
    def delete_sec(self, id):
        res = requests.delete(url=self.url_id.format(id), headers=self.header_dict)
        logging.info("删除部门接口返回的数据:{}".format(res.json()))
        return res
